Budapest Public Transport Map

Table of content:

Intro

Hi there! Thanks for checking out my mini-project about Budapest Public Transport. The aim of this notebook is to visualize GTFS data specific to Budapest. The methods & functions used here are universal, and therefore, can be used on any other GTFS data.

General Transit Feed Specification (GTFS) is a widely used data specification framework that enables a common data format to be used by agencies to publish their transit data to be consumed by softwares. Budapest Közlekedési Központ (BKK), the transport agency of Budapest, publishes the transit data using the GTFS specification. GTFS has a rich metadata, therefore, it is easy to use and to implement for projects like this one.

In this project I attempt to enrich the GTFS data with geojson specifications of the different jurisdicial districts in Budapest. I will use the districts to create on the map. One could use this filter to know which vehicles enter/leave a specific district.

Furthermore, I will briefly introduce the libraries I used to create a map of routes in Budapest. Then, I will briefly discuss the functions to download, extract & enrich GTFS data. Then, I will show the transformations I added to the data. Lastly, the results section showcases the map produced.

Packages

There are briefly 3 categories of packages used for this project: one for data extraction, one for data manipulation & one for visualization.\ For data extraction I used 'requests', which allows for downloading specific content from a website. Then I used 'zipfile' to extract the content of the downloaded file. Moreover, basic commands are used from 'os' pkg.\ For data manipulation I used 'pandas', which is the de-facto package on python that uses sql-like transformations to manipulate data. Since I am working with geometrical shapes, points and lines, I used 'geopandas' and 'shapely' to work with geospatial data.\ For visualization, I used the 'keplergl' which creates beautiful maps from geospatial data.

Functions

To download the data from a website, one could easily use the get function from the requests package. get_gtfs function uses the GET command to download and write the .zip file to a specified directory, after which it extracts it to the very same folder.

read_file function will parse the downloaded .txt files into geopandas dataframes enriched with geospatial data. If the stops.txt is being read, then the district shapes are added to the geopandas dataframe.

Data transformation

The routes dataframe contains descriptive data about each line BKK operate. Merging it with shapes, trips & stop_times creates a large dataframe containing all relevant information about each route. It contains geospatial data for each line, the route name, its type and its color code attributed by BKK. Each route is duplicated across the districts it ventures into.

Results

KeplerGL is, in my opinion, the best package for creating beautiful maps in Python. Check it out here!\ Using keplerGL, I mapped the linestring for each route to the coordinates of Budapest. One can filter on each district to see which routes enter/leave a specific district.

I also used the HEX codes provided by BKK for each route to color the routes. To save the changes, just simply add the congifurations to the map via the code below. Then, you can save the map you created in an html.

Here are the results! An accurate representation of each route in Budapest. As it can be seen, Budapest highly depends on its bus lines (blue color), while trolleys (red) & trams (yellow) dominate the inner city.

title